package com.lc.hongtai.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lc.hongtai.MyApplication;
import com.lc.hongtai.R;
import com.lc.hongtai.conn.JsonInterest;
import com.zcx.helper.bound.BoundViewHelper;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 3/16/2016.
 */
public class IncreasedInterestAdapter extends RecyclerView.Adapter<IncreasedInterestAdapter.ViewHolder> {

    private Context context;
    private List<JsonInterest.Info.ListContent> list;

    public IncreasedInterestAdapter(Context context, List<JsonInterest.Info.ListContent> list) {
        this.context = context;
        this.list = list;
    }


    // Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
    public static class ViewHolder extends RecyclerView.ViewHolder {
        // each data item is just a string in this case

        @Bind(R.id.tv_01)
        TextView tv01;
        @Bind(R.id.tv_02)
        TextView tv02;
        @Bind(R.id.tv_03)
        TextView tv03;

        @Bind(R.id.back_ground_jiaxi)
        LinearLayout back_ground_jiaxi;
        @Bind(R.id.text_status)
        TextView text_status;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = BoundViewHelper.boundView(this, MyApplication.scaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_13_item_view, null)));
        // set the view's size, margins, paddings and layout parameters
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }


    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv01.setText(list.get(position).interest_rate);

        holder.text_status.setText("加息");


        if (list.get(position).status_cn.equals("已使用")) {
            holder.tv02.setTextColor(context.getResources().getColor(R.color.colorGreydividingline));
        } else if (list.get(position).status_cn.equals("已禁用")) {
            holder.tv02.setTextColor(context.getResources().getColor(R.color.colorGreydividingline));
        } else {
            holder.tv02.setTextColor(context.getResources().getColor(R.color.colorForgotPink));
        }
        if (list.get(position).status.equals("1")) {

            holder.back_ground_jiaxi.setBackgroundResource(R.mipmap.jiaxiquanunselected);

        } else {

            holder.back_ground_jiaxi.setBackgroundResource(R.mipmap.jiaxiquan_selected);

        }

        holder.tv02.setText(list.get(position).status_cn);


          holder.tv03.setText(list.get(position).start_time + "-" + list.get(position).end_time);
    }

    /**
     * Returns the total number of items in the data set hold by the adapter.
     *
     * @return The total number of items in this adapter.
     */
    @Override
    public int getItemCount() {
        return list.size();
    }
}